package com.xmh.demo.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.xmh.demo.entity.UserQianmeiEntity;
import com.xmh.demo.service.UserQianmeiService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * @author xiaominghui
 * @Date 2020-08-09 12:27:03
 */
@CrossOrigin
@Api(tags = "UserQianmeiController")
@RestController
@RequestMapping(value = "/API/userQianmei", produces = "application/json;charset=UTF-8")
@Transactional

public class UserQianmeiController {

    @Autowired
    private UserQianmeiService userQianmeiService;

    /**
     * 保存数据接口
     *
     * @param jsonMap
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "保存接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> save(@RequestBody Map<String, Object> jsonMap) throws Exception {
        UserQianmeiEntity userQianmeiParameter = new UserQianmeiEntity(jsonMap);

        return userQianmeiService.add(userQianmeiParameter);
    }

    /**
     * 根据给定数据条件删除数据，不一定根据id删除
     *
     * @param jsonMap
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> delete(@RequestBody Map<String, Object> jsonMap) throws Exception {
        UserQianmeiEntity userQianmeiParameter = new UserQianmeiEntity(jsonMap);

        return userQianmeiService.delete(userQianmeiParameter);
    }

    /**
     * update修改接口，根据唯一id进行修改
     *
     * @param jsonMap
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ApiOperation(value = "修改接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> update(@RequestBody Map<String, Object> jsonMap) throws Exception {
        UserQianmeiEntity userQianmeiParameter = new UserQianmeiEntity(jsonMap);

        return userQianmeiService.update(userQianmeiParameter);
    }

    /**
     * 查找多条数据，条件可以为空，默认查找全部
     *
     * @param jsonMap <pre>
     *                	pageIndex 页数下标
     *                	pageNumber 每页数量
     *                               </pre>
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/selectList", method = RequestMethod.POST)
    @ApiOperation(value = "获取列表接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> selectList(@RequestBody Map<String, Object> jsonMap) throws Exception {
        Map<String, Object> map = new HashMap<String, Object>();

        map.put("list", userQianmeiService.selectList(jsonMap));

        return map;
    }

    /**
     * 根据指定条件获取单条数据
     *
     * @param jsonMap
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/get", method = RequestMethod.POST)
    @ApiOperation(value = "获取单体数据接口", notes = "参数 ： ")
    @ResponseBody
    public Map<String, Object> get(@RequestBody Map<String, Object> jsonMap) throws Exception {
        UserQianmeiEntity userQianmeiParameter = new UserQianmeiEntity(jsonMap);

        Map<String, Object> map = new HashMap<String, Object>();

        map.put("entity", userQianmeiService.get(userQianmeiParameter));

        return map;
    }

}
